<?php

namespace App\Http\Middleware;

use App\Models\Category;
use Cache;
use Closure;

class GetCategory
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $cacheName        = md5('category');
        $data['category'] = Cache::remember($cacheName, 86400000000, function () {
            $objCategory = new Category();
            return $objCategory->getTree();
        });
        view()->share('data', $data);
        return $next($request);

    }
}
